package com.bbu.javaexam.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bbu.javaexam.dao.ExamManageMapper;
import com.bbu.javaexam.dao.FillQuestionMapper;
import com.bbu.javaexam.dao.JudgeQuestionMapper;
import com.bbu.javaexam.dao.MultiQuestionMapper;
import com.bbu.javaexam.domain.ExamManage;
import com.bbu.javaexam.service.ExamManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Alex
 * @version 1.0.0
 * @ClassName ExamManageServiceImpl.java
 * @Description TODO
 */
@Service
public class ExamManageServiceImpl extends ServiceImpl<ExamManageMapper, ExamManage> implements ExamManageService {
    @Autowired
    private ExamManageMapper examManageMapper;

    @Autowired
    private FillQuestionMapper fillQuestionMapper;

    @Autowired
    private JudgeQuestionMapper judgeQuestionMapper;

    @Autowired
    private MultiQuestionMapper multiQuestionMapper;

    @Override
    public List<ExamManage> findAll() {
        return examManageMapper.findAll();
    }

    @Override
    public IPage<ExamManage> findAll(Page<ExamManage> page) {
        return examManageMapper.findAll(page);
    }

    @Override
    public ExamManage findById(Integer examCode) {
        return examManageMapper.findById(examCode);
    }

    @Override
    public int delete(Integer examCode) {
        return examManageMapper.delete(examCode);
    }

    @Override
    public int update(ExamManage exammanage) {
        return examManageMapper.update(exammanage);
    }

    @Override
    public int add(ExamManage exammanage) {
        return examManageMapper.add(exammanage);
    }

    @Override
    public ExamManage findOnlyPaperId() {
        return examManageMapper.findOnlyPaperId();
    }

    @Override
    public int deletetimu(Integer examCode, String type) {
        if ("填空题".equals(type)) {
            fillQuestionMapper.deleteById(examCode);
        } else if ("选择题".equals(type)) {
            multiQuestionMapper.deleteById(examCode);
        } else if ("判断题".equals(type)) {
            judgeQuestionMapper.deleteById(examCode);
        }
        return 0;
    }
}
